import 'package:flutter/material.dart';
import 'dart:async';
enum Option{
A,B,C
  }
class MyDialog extends StatefulWidget{
  @override
    MyDialogState createState() {
      // TODO: implement createState
      return MyDialogState();
    }
}

class MyDialogState extends State<MyDialog>{
  final _bottomSheet=GlobalKey<ScaffoldState>();
  String _chioce="nothing";
  Future _showDialog() async{
     final option=await showDialog(
      context: context,
      builder: (BuildContext context){
        return SimpleDialog(
          
          children: <Widget>[
            SimpleDialogOption(
              child: Text("OptionA"),
              onPressed: (){
                Navigator.pop(context,Option.A);
              },
            ),
            SimpleDialogOption(
              child: Text("OptionB"),
              onPressed: (){
                Navigator.pop(context,Option.B);
              },
            ),
            SimpleDialogOption(
              child: Text("OptionC"),
              onPressed: (){
                Navigator.pop(context,Option.C);
              },
            )
          ],
          title: Text("简单的对话框"),);
      }
    );
      switch(option){
        case Option.A:
          setState(() {
            _chioce='A';
          });
          break;
          case Option.B:
          setState(() {
            _chioce='B';
          });
          break;
          case Option.C:
          setState(() {
            _chioce='C';
          });
          break;
      }
  }
  _showAlerDialog(){
    showDialog(
      context:context,
      builder: (BuildContext context){
        return AlertDialog(
          title: Text("Alert对话框标题"),
          content: Text("Alert对话框内容"),
          actions: <Widget>[
            FlatButton(
              child: Text("确认"),
              onPressed: (){
                Navigator.pop(context);
              },
            ),
            FlatButton(
              child: Text("取消"),
              onPressed: (){
                Navigator.pop(context);
              },
            ),
          ],
        );
      }
    );
  }
  _showBottomAlertDialog(){
    _bottomSheet.currentState.showBottomSheet(
      (BuildContext context){
        return Container(
          height: 60.0,
          padding: EdgeInsets.all(10),
          decoration: BoxDecoration(
            border: Border.all(color: Colors.grey)
          ),
          child: Row(
            children: <Widget>[
              Icon(Icons.pause),
              SizedBox(width: 10,),
              Text("01:22/05:33"),
              Expanded(
                child: Text("寂寞沙洲冷/周传雄",textAlign: TextAlign.end,),
              )
            ],
          ),
        );
      }
    );
  }
  _showBottomModelDialog(){
    showModalBottomSheet(
      context: context,
      builder: (BuildContext context){
        return Container(
          height: 200,
          child: Column(
            children: <Widget>[
              ListTile(
                title: Text("Option A"),
              ),
              ListTile(
                title: Text("Option B"),
              ),
              ListTile(
                title: Text("Option C"),
              )
            ],
          )
          );
      }
    );
  }
  @override
    Widget build(BuildContext context) {
      // TODO: implement build
      return Scaffold(
        key: _bottomSheet,
        appBar:AppBar(
          title:Text("对话框")
        ),
        body: Center(
          child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
             Text("Which you choice is :$_chioce"),
             RaisedButton(
               child: Text("Alert对话框"),
               onPressed: _showAlerDialog,
             ),
             FlatButton(
               child: Text("底部bottomSheet"),
               onPressed: _showBottomAlertDialog,
             ),
            //  RaisedButton(
            //    child: Text("底部ModelSheet"),
            //    onPressed: _showBottomModelDialog,
            //    )
          ],
        ),
        ),
        floatingActionButton:FloatingActionButton(
          child: Icon(Icons.menu),
          onPressed: _showDialog,
        ),
        
        
        
      );
    }
}
